﻿using ARSoft.Tools.Net;
using ARSoft.Tools.Net.Dns;
using ARSoft.Tools.Net.Dns.DynamicUpdate;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Net;
using System.Text;
using System.Threading;

namespace DnsUpdate
{
    class Program
    {
        static void Main(string[] args)
        {
            DnsClient client = new DnsClient(IPAddress.Parse("61.139.2.69"), 5000);
            while (true)
            {
                ushort num = 0;
                var req = new ARSoft.Tools.Net.Dns.DynamicUpdate.DnsUpdateMessage
                {
                    TransactionID = num++,
                    OperationCode = OperationCode.Update,
                };

                var d = DomainName.Parse("sandsea.info");
                req.Updates.Add(new DeleteRecordUpdate(new ARecord(d, 60 * 5, IPAddress.Parse("192.168.1.1"))));
                req.Updates.Add(new AddRecordUpdate(new ARecord(d, 60 * 5, IPAddress.Parse("127.0.0.1"))));
                //req.Updates.Add(new DeleteAllRecordsUpdate(d));
                req.ZoneName = DomainName.Parse("61.139.2.69");
                var resp = client.SendUpdate(req);
                if (resp == null)
                {
                    Console.WriteLine("Unsupported");
                }
                else
                    Console.WriteLine(resp.ReturnCode);
                //Thread.Sleep(250);
            }
        }
    }
}
